package com.codermn.demo8;

import java.io.File;
import java.io.FileFilter;

/**
 * @author jxau_scf
 * @date 2021/6/27 - 16:34
 */
public class Testfile {
    public static void main(String[] args) {
        File file = new File("E:\\Worksapces\\idea2019.3.1\\homework\\src\\com\\codermn\\demo3");
        getAllFile(file);
    }



    private static void getAllFile(File dir) {
        System.out.println("被遍历的目录名称："+dir);
        File[] files = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory()) {
                    return true;
                }
                return pathname.getName().toLowerCase().endsWith(".java");
            }
        });
        for (File file : files){
            if (file.isDirectory()){
                getAllFile(file);
            }else {
                System.out.println(file);
            }
        }
    }
}
